package springmvcdemo.controller;


import jakarta.servlet.http.HttpSession;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/user")
@RestController
public class LoginController {
    @RequestMapping("/login")
    public boolean login(String userName, String password, HttpSession session) {
        //验证账号密码是否正确，用户名为：大牛，密码为：123456
        //1.判空
        if(!StringUtils.hasLength(userName) || !StringUtils.hasLength(password)) return false;
        //2.判断相等
        if(!"123456".equals(password) || !"大牛".equals(userName)) return false;
        session.setAttribute("userName",userName);//设置session，用户后续的返回页面使用
        return true;
    }

    @RequestMapping("/getUserInfo")
    public String getUerInfo(HttpSession session) {
        String userName = (String) session.getAttribute("userName");
        System.out.println("用户登陆："+userName);
        return userName;
    }
}
